package com.github.cyf.controller;

import com.github.cyf.common.model.Rs;
import com.github.cyf.webSocket.WebSocketServer;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;

/**
 * @author chenyifan
 * @create 2025-03-17 11:05
 */
@RestController("/push")
public class PushController {

    @GetMapping("/socket/push/{sid}")
    public Rs pushMessage(@PathVariable("sid") String sid, String message) {
        WebSocketServer.sendMessageToUser(sid, message);
        return Rs.ok("推送成功");
    }

    @GetMapping("/socket/push/allUser")
    public Rs pushAllUserMessage(String message) throws IOException {
        WebSocketServer.sendMessageToAll(message);
        return Rs.ok("推送成功");
    }
}
